#include "StdAfx.h"
#include "GSUserManagerCL.h"

GSUserManagerCL::GSUserManagerCL(void)
{
}

GSUserManagerCL::~GSUserManagerCL(void)
{
}

void GSUserManagerCL::AddUser(GSUserCLPtr user_) 
{
	unsigned int userID = user_->GetUserID() ;
	m_userMap[userID] = user_ ;
}

GSUserCLPtr GSUserManagerCL::GetUser(unsigned int userID_) 
{
	std::map<unsigned int , GSUserCLPtr>::iterator it ;

	it = m_userMap.find(userID_) ;
	if(it != m_userMap.end())
	{
		return it->second ;
	}

	return NULL ;
}

bool GSUserManagerCL::DelUser(unsigned int userID_)
{
	std::map<unsigned int , GSUserCLPtr>::iterator it ;

	it = m_userMap.find(userID_) ;
	if(it != m_userMap.end())
	{
		it->second = NULL ;
		m_userMap.erase(it) ;
		return true ;
	}

	return false ;
}

void GSUserManagerCL::PushTempUser(std::string name_ , GSUserCLPtr user_) 
{
	m_tempUserMap[name_] = user_ ;
}

GSUserCLPtr GSUserManagerCL::PopTempUser(std::string name_) 
{
	GSUserCLPtr retPtr = NULL ;

	std::map<std::string  , GSUserCLPtr>::iterator it ;

	it = m_tempUserMap.find(name_) ;
	if(it != m_tempUserMap.end())
	{
		retPtr = it->second ;
		it->second = NULL ;
		m_tempUserMap.erase(it) ;
	}

	return retPtr ;
}

void GSUserManagerCL::PushLoginCBToMap(std::string name_ , AMD_UserLogin_LoginPtr cb_) 
{
	m_loginCBMap[name_] = cb_ ;
}

AMD_UserLogin_LoginPtr GSUserManagerCL::PopLoginCBFromMap(std::string name_)
{
	AMD_UserLogin_LoginPtr retPtr = NULL ;

	std::map<std::string , AMD_UserLogin_LoginPtr>::iterator it ;

	it = m_loginCBMap.find(name_) ;
	if(it != m_loginCBMap.end())
	{
		retPtr = it->second ;
		it->second = NULL ;
		m_loginCBMap.erase(it) ;
	}

	return retPtr ;
}